package com.wxl.micro.service.order.controller;

import com.alibaba.csp.sentinel.slots.block.Rule;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRuleManager;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRuleManager;
import com.alibaba.csp.sentinel.slots.system.SystemRule;
import com.alibaba.csp.sentinel.slots.system.SystemRuleManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sentinel")
public class SentinelConfigController {


    @GetMapping("/config")
    public Object getCacheConfig(){

        List<FlowRule> rules1 = FlowRuleManager.getRules();
        List<DegradeRule> rules2 = DegradeRuleManager.getRules();
        List<ParamFlowRule> rules3 = ParamFlowRuleManager.getRules();
        List<AuthorityRule> rules4 = AuthorityRuleManager.getRules();
        List<SystemRule> rules5 = SystemRuleManager.getRules();


        Map<String,Object> map = new HashMap<>();
        map.put("限流规则",rules1);
        map.put("降级规则",rules2);
        map.put("热点规则",rules3);
        map.put("授权规则",rules4);
        map.put("系统规则",rules5);

        return map;
    }
}
